package com.itany.corejava.code14_lambda;

import com.itany.corejava.code13_jdbc.User;

import java.util.function.Supplier;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年08月09日13:49
 */
public class Test07_构造方法的引用 {
    public static void main(String[] args) {
        Supplier<User> s=new Supplier<User>() {
            @Override
            public User get() {
                return new User();
            }
        };

        // System.out.println(s.get());

        //调用无参构造方法
        // User user=new User();
        // System.out.println(user);

        Supplier<User> ss=User::new;
        User user=ss.get();
        System.out.println(user);

        // AA<String,Stu> aa=new AA<String, Stu>() {
        //     @Override
        //     public Stu show(String t1, String t2, String t3) {
        //         return new Stu(t1,t2,t3);
        //     }
        // };
        //
        // System.out.println(aa.show("admin","123","南京"));
        // AA<String,Stu> aa2=(t1,t2,t3)->new Stu(t1,t2,t3);

        AA<String,Stu> aa2=Stu::new;
        System.out.println(aa2.show("lucy","123","北京"));
    }
}


@FunctionalInterface
interface AA<T,R>{
    R show(T t1,T t2,T t3);
}


class Stu{
    private String username;
    private String password;
    private String address;

    public Stu(String username, String password, String address) {
        this.username = username;
        this.password = password;
        this.address = address;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
